import { type Ref, ref, onMounted } from "vue"
import type { IGoods } from "@/types/type"
import { RequestShopList } from "@/apis/index"
import { useRouter } from "vue-router"
export const useShopList = () => {
    const shoplist: Ref<Array<IGoods>> = ref([])
    const getShopList = async (pageNo: number, pageSize: number) => {
        const data = await RequestShopList(pageNo, pageSize)
        const { resultCode, resultInfo } = data
        if (resultCode === 1) {
            shoplist.value = [...shoplist.value, ...resultInfo.list]
        }

    }
    onMounted(() => {
        getShopList(1, 50)
    })
    //返回上一级
    const onClickLeft=()=>history.back()
    //跳转
    const router=useRouter()
    const bindJump=(id:number)=>{
            router.push({path:'/detail',query:{id,}})
       
        
    }
    return { shoplist, getShopList,onClickLeft,bindJump }
}